package com.boe.common.jdbc;

import org.springframework.context.annotation.Conditional;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Component;
import lombok.*;

import java.sql.*;
import java.util.LinkedHashMap;
import java.util.Map;

@Component
@Conditional(ExistsSqlSourceConfigCondition.class)
public class JsonMapRowMapper implements RowMapper<Map> {
    @Override
    public Map mapRow(ResultSet rs, int rowNum) throws SQLException {
        var ret = new LinkedHashMap<String, Object>();
        var meta = rs.getMetaData();
        for (Integer i = 1; i <= meta.getColumnCount(); i++) {
            ret.put(meta.getColumnLabel(i), rs.getObject(i));
        }
        return ret;
    }
}